import { SchedulerApi } from '@/api'
import { TIMER_FORMAT } from '@/constants'
import moment from 'moment'

export class SchedulerService {
  static create(data) {
    const { time } = data
    let extraTime = {}
    if (time) {
      extraTime = {
        start_time: moment(time[0]).format(TIMER_FORMAT),
        end_time: moment(time[1]).format(TIMER_FORMAT),
        time: undefined
      }
    }
    return SchedulerApi.create({ ...data, ...extraTime })
  }
  static query(params) {
    return SchedulerApi.query({
      ...params,
      page: params.offset / params.limit + 1,
      offset: undefined,
      random: undefined
    }).then(({ data = {} }) => {
      return {
        data: data.items,
        total: data.total
      }
    })
  }
  static queryHandleList(params) {
    return new Promise((resolve, reject) => {
      resolve({
        data: [
          {
            name: '威胁名称1',
            level: '低危',
            type: 'web',
            tag: ['标签1'],
            status: '手动结束',
            result: '处置成功',
            time: '123s',
            start_time: '2022-05-31 11:12:13',
            end_time: '2022-05-31 11:12:13',
            admin: 'admin'
          }
        ],
        total: 1
      })
    })
  }
}
